package karileet.meeting.profile.fragment;
import karileet.meeting.profile.ProfileConf;
import karileet.meeting.profile.SoundManager;
import karileet.meeting.profile.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class VolumeFragment extends DialogFragment {
	private int beepVolume;
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		
	    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
	    // Get the layout inflater
	    LayoutInflater inflater = getActivity().getLayoutInflater();
//	    getDialog().setTitle("Notification settings");
	    builder.setTitle(R.string.volume_title);
	    // Inflate and set the layout for the dialog
	    // Pass null as the parent view because its going in the dialog layout
	    View v = inflater.inflate(R.layout.volume_fragment, null);
	    SeekBar sb = (SeekBar) v.findViewById(R.id.seekBar1);
        final ProfileConf state = new ProfileConf(getActivity());
        beepVolume = state.getBeepVolume();
        sb.setMax(15);
        sb.setProgress(beepVolume);
        sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onStartTrackingTouch(SeekBar arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onStopTrackingTouch(SeekBar arg0) {
				//store new beep volume
				beepVolume = arg0.getProgress();
				
				//and play example
				SoundManager sm = new SoundManager(getActivity());
				sm.play(beepVolume);
			} 
        	
        });
	    builder.setView(v)
	    // Add action buttons
	           .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
	               @Override
	               public void onClick(DialogInterface dialog, int id) {
	            	   state.setBeepVolume(beepVolume);
	               }
	           }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
	               @Override
	               public void onClick(DialogInterface dialog, int id) {
	               }
	           });   
	    return builder.create();
	}
}
